<?php

/**
 * Description of SinaAdmin
 *
 * @author Administrator
 */
class SinaUserAdmin extends BaseAction{
    function actionIndex() {
        $this->setPageTitle('新浪短网址');
        $this->render();
    }
    
    /**
     * 刷新微博评论、分享统计
     * 短链接在微博上的微博分享数
     * 取得一个短链接在微博上的微博评论数 
     */
    function actionFlushWeiboCount(){
        $arr    = array('code' =>'error');
        $url    = $this->params['url'];
        $date   = time();
        $diff   = 10 ;
        if(!array_key_exists('flush_time', $_SESSION)) {
            $this->setSession('flush_time', $date);
        }else{
            $diff   = time() - $_SESSION['flush_time'];
        }
        
        if($url && $diff > 10) {
            $comment    = get_action('front', 'SinaShortUrlCommentCounts',array('url' =>$url));
            $comment    = json_decode($show);
            $share      = get_action('front', 'SinaShortUrlShareCounts',array('url' =>$url));
            $share      = json_decode($share);
            $arr['code'] = 'ok';
            $arr['comment'] = (int)$show->comment_counts;
            $arr['share']   = (int)$show->share_counts;
            $this->setSession('flush_time', time());
        }else{
            $arr['msg'] = '请10秒后刷新';
        }
        echo json_encode($arr);
    }
    
    /**
     * 更新微博评论、分享统计
     * 短链接在微博上的微博分享数
     * 取得一个短链接在微博上的微博评论数 
     */
    function actionUpdateWeiboCount(){
        $share_counts   = $this->params['share_counts'];
        $comment_counts = $this->params['comment_counts'];
        $url            = $this->params['url'];
        
        $sql    = "update {#prefix#}short_url_comment_counts set counts=$comment_counts where url=?";
        $sql    = DAO_Finder::query_sql($sql,array($comment_counts), DB_SHORT_URL_COMMENT_COUNTS);
        
        $sql    = "update {#prefix#}short_url_share_counts set counts=$share_counts where url=?";
        $sql    = DAO_Finder::query_sql($sql,array($share_counts),  DB_SHORT_URL_SHARE_COUNTS);
    }
}

?>
